<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQueryEnter">
        <a-row :gutter="24">
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="工单ID">
              <a-input placeholder="请输入工单ID" v-model="queryParam.woId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <a-form-item label="箱号编码">
              <a-input placeholder="请输入箱号编码" v-model="queryParam.lotNo"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">

          </template>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->


    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="recId"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type:'radio'}"
        class="j-table-force-nowrap"
        :customRow="clickThenSelect"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text,record">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <span slot="status" slot-scope="text">
          <a-tag
            :color="text === '运行' ? 'green' : text === '关闭' ? '#e1dede' : '#c5833d'"
          >
            {{ text }}
          </a-tag>
        </span>
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)" v-has="'MesWoSrc:edit'">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record)" v-has="'MesWoSrc:delete'">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>
    <a-tabs defaultActiveKey="1" style="width: 50%;float: left">
      <a-tab-pane tab="中盒包装历史" key="1">
        <PackageMiddleBoxList :fatherCode="middleBoxMainId" :woId="woId" @itemClick="itemClick" />
      </a-tab-pane>
    </a-tabs>
    <a-tabs defaultActiveKey="1" style="width: 50%;float: right">
      <a-tab-pane tab="产品包装历史" key="1">
        <PackageProductList :fatherCode="productMainId" :woId="woId" />
      </a-tab-pane>
    </a-tabs>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import PackageMiddleBoxList from './modules/PackageMiddleBoxList.vue'
import PackageProductList from './modules/PackageProductList.vue'
import { filterMultiDictText } from '@/components/dict/JDictSelectUtil'

export default {
  name: 'PackageTrace',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    PackageMiddleBoxList,
    PackageProductList
  },
  data() {
    return {
      description: '包装追溯',
      queryParam: {
        unit: '1'
      },
      /* 分页参数 */
      ipagination: {
        current: 1,
        pageSize: 5,
        pageSizeOptions: ['5', '10', '50'],
        showTotal: (total, range) => {
          return range[0] + '-' + range[1] + ' 共' + total + '条'
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '产线或产线组',
          align: 'center',
          dataIndex: 'line'
        },
        {
          title: '工单ID',
          align: 'center',
          dataIndex: 'woid'
        },
        {
          title: '箱号',
          align: 'center',
          sorter: true,
          dataIndex: 'lotno'
        },
        {
          title: '产品或产品组',
          align: 'center',
          dataIndex: 'partno'
        },
        {
          title: '批次数量',
          align: 'center',
          dataIndex: 'qty'
        },
        {
          title: '当前批次数量',
          align: 'center',
          dataIndex: 'qtyCur'
        },
        {
          title: '产品数量',
          align: 'center',
          dataIndex: 'productQty'
        },
        {
          title: '班次',
          align: 'center',
          dataIndex: 'shift'
        },
        {
          title: '班次日期',
          align: 'center',
          dataIndex: 'shiftDate'
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status'
        },
        {
          title: '类型',
          align: 'center',
          dataIndex: 'unit'
        },
        {
          title: '重量',
          align: 'center',
          dataIndex: 'weight'
        },
        {
          title: '更新时间',
          align: 'center',
          sorter: true,
          dataIndex: 'ctime'
        }
      ],
      url: {
        list: '/trace/packageTrace/listBoxPackage'

      },
      woId: '',
      selectedMainId: '',
      middleBoxMainId: '',
      productMainId: '',
      dictOptions: {},
      superFieldList: []
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    itemClick(record) {
      this.productMainId = record.lotno
      this.woId = record.woid
    },
    searchQueryEnter() {
      if (this.queryParam.lotNo.indexOf('|') >= 0) {
        let arr = this.queryParam.lotNo.split('|')
        this.queryParam.woId = arr[2]
        this.queryParam.lotNo = arr[0] + '|' + arr[4] + '|' + arr[5]
      }
      this.loadData(1)
      this.selectedRowKeys = []
      this.selectionRows = []
    },
    searchReset() {
      this.queryParam = {
        unit: '1'
      }
      this.loadData(1)
    },
    clickThenSelect(record) {
      return {
        on: {
          click: () => {
            this.onSelectChange(record.recId.split(','), [record])
          }
        }
      }
    },
    onClearSelected() {
      this.selectedRowKeys = []
      this.selectionRows = []
      this.selectedMainId = ''
    },
    onSelectChange(selectedRowKeys, selectionRows) {
      this.middleBoxMainId = selectionRows[0].lotno
      this.productMainId = selectionRows[0].lotno
      this.woId = selectionRows[0].woid
      this.selectedRowKeys = selectedRowKeys
      this.selectionRows = selectionRows
    },
    initDictConfig() {
    },
    getSuperFieldList() {
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>